//
//  MBVipPopView.m
//  Meboo
//
//  Created by kyo on 2024/3/13.
//

#import "MBVipPopView.h"
@interface MBVipPopView ()
@property(nonatomic,strong) UIImageView *backImageView;
@property(nonatomic,strong) UILabel *titleLab;
@property(nonatomic,strong) UILabel *subTitleLab;
@property(nonatomic,strong) UIButton *getBtn;
@end
@implementation MBVipPopView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Private Method


#pragma mark - Action
-(void)closePop {
    self.hidden = YES;
}

//- (void)saveAction {
//    [self closePop];
//    //存储然后跳转
//    KLUserAccount  *account = [KLUserAccount defaultAccount];
//    //去掉第一位的空格
//    if ([[self.nickNameStr substringToIndex:1] isEqualToString:@" "]) {
//        self.nickNameStr = [self.nickNameStr substringFromIndex:1];
//    }
//    
//    //去掉最后一位的空格
//    if ([[self.nickNameStr substringFromIndex:self.nickNameStr.length-1] isEqualToString:@" "]) {
//        self.nickNameStr = [self.nickNameStr substringToIndex:self.nickNameStr.length-1];
//    }
//    
//    account.nickName = self.nickNameStr;
//    [KLUserAccount  saveAccount:account];
//    
//    [[KLLoginApiManager sharedManager] changeUserInfoWithKey:@"nickName" value:account.nickName Success:^(BOOL success) {
//        
//    }];
//    if (self.saveBlock) {
//        self.saveBlock(self.nickNameStr);
//    }
//}
#pragma mark - UI
- (void)setupUI {
    self.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.5];
    
    [self addSubview:self.backImageView];
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(MBHeightScale(-48));
        make.centerX.equalTo(self);
        make.height.mas_equalTo(MBHeightScale(277));
        make.left.mas_equalTo(MBWidthScale(58));
    }];
    
    [self.backImageView addSubview:self.getBtn];
    [self.getBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(24));
        make.centerX.equalTo(self);
        make.height.mas_equalTo(MBHeightScale(37));
        make.bottom.mas_equalTo(MBHeightScale(-12));
    }];
    
    [self.backImageView addSubview:self.subTitleLab];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.getBtn.mas_top).offset(MBHeightScale(-20));
    }];
    
    [self.backImageView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.subTitleLab.mas_top).offset(MBHeightScale(-10));
    }];
}

#pragma mark - Setter && Getter

- (UIImageView *)backImageView {
    if (!_backImageView) {
        _backImageView = [UIImageView new];
        _backImageView.userInteractionEnabled = YES;
        _backImageView.image = ImageWithName(@"vipprofile_vip_pop_back");
    }
    return _backImageView;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.font = PDBoldScale(18);
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.textColor = HEXS(@"C07013");
        _titleLab.text = @"Welcome to Meboo";
    }
    return _titleLab;
}

- (UILabel *)subTitleLab {
    if (!_subTitleLab) {
        _subTitleLab = [UILabel new];
        _subTitleLab.numberOfLines = 0;
        _subTitleLab.textAlignment = NSTextAlignmentCenter;
        _subTitleLab.font = PDRegularScale(16);
        _subTitleLab.textColor = HEXS(@"C17013");
        _subTitleLab.text = @"You have successfully\nsubscribed enjoy the benefits";
    }
    return _subTitleLab;
}

- (UIButton *)getBtn {
    if (!_getBtn) {
        _getBtn = [UIButton new];
        [_getBtn setTitle:@"Get it" forState:0];
        [_getBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_getBtn setTitleColor:HEXS(@"FFEBC5") forState:0];
        _getBtn.titleLabel.font = PDBoldScale(15);
        [_getBtn setBackgroundColor:HEXS(@"C07013")];
        _getBtn.layer.cornerRadius = MBHeightScale(18.5);
        [_getBtn addTarget:self action:@selector(closePop) forControlEvents:UIControlEventTouchUpInside];
    }
    return _getBtn;
}
@end
